10 ' fracdeci.bas - FreeWare 2006 - Eric F. Tchong
20 GOTO 80 ' begin
30 SAVE "fracdeci.bas",A:LIST-80
40 GOTO 600 ' wait for key
50 GOTO 630 ' text
60 GOTO 650 ' clear line
70 ' begin
80 CLS:KEY OFF:DIM DG(999),RM(999):DEFSTR M,Q:Q=MKI$(0)
90 M(1) ="FRACTIONS TO DECIMALS CONVERTER"
100 M(2) ="examples: 1/3  22/5    1/7 "
110 M(3) ="          3/8  45/56  11/59"
120 M(4) ="Do you need a diskfile: <y/n> ?":CLS:LOCATE 2,1
130 FOR I=1 TO 4
140  GOSUB 50:IF I=3 THEN PRINT
150 NEXT:GOSUB 40:GOSUB 60 ' clear line
160 IF ASC(Q)=89 OR ASC(Q)=121 THEN CP=1 ELSE CP=0 ' CP = copy
170 IF CP THEN 180 ELSE 230
180 PRINT "Type a filename <12345678.txt> ? ";:LINE INPUT Z$
190 IF LEFT$(Z$,1)=" " THEN Z$=MID$(Z$,2):GOTO 190
200 OPEN "O",#1,Z$:GOSUB 60:GOTO 230
210 ' Scan for correct input
220 BEEP:GOSUB 60
230 INPUT "Fraction: <0=Exit> ";A$
240 IF A$="0" OR A$="" THEN CLS:END
250 NU=VAL(A$):Z=LEN(STR$(NU))+1:DE=VAL(MID$(A$,Z))
260 IF NU=0 OR DE=0 THEN 220
270 IF NU<>INT(NU)  THEN 220
280 IF DE<>INT(DE)  THEN 220
290 ' Convert fraction to decimal
300 GOSUB 60:PRINT A$; " = ";:IF CP THEN PRINT #1, A$; " = ";
310 IF NU<DE THEN 340
320 A=INT(NU/DE):PRINT STR$(A);:IF CP THEN PRINT #1, STR$(A);
330 NU=NU-A*DE
340 NU=NU*10
350 FOR L=0 TO 999
360  IF NU=0 THEN L=L-1:FL=0:GOTO 460 ' FL=0  No repetitions
370  RM(L)=NU:DG(L)=INT(NU/DE):NU=10*(NU-DG(L)*DE)
380  FOR L2=0 TO L
390   IF NU=RM(L2) THEN FL=1:GOTO 460 ' FL=1 Yes repetitions
400  NEXT
410 NEXT
420 PRINT "No repetitions in first 1000 digits.":PRINT
430 IF CP THEN PRINT #1, "No repetitions in first 1000 digits.":PRINT #1,
440 GOTO 230
450 ' 12/6 = 2 not 2. Skip .
460 IF L=-1 THEN 560
470 PRINT ".";:IF CP THEN PRINT #1, ".";
480 FOR Z=0 TO L
490  IF FL AND L2=Z THEN PRINT "(";:IF CP THEN PRINT #1, "(";
500  PRINT RIGHT$(STR$(DG(Z)),1);
510  IF CP THEN PRINT #1, RIGHT$(STR$(DG(Z)),1);
520 NEXT:IF FL THEN PRINT ")":IF CP THEN PRINT #1, ")"
530 IF FL=0 OR L<6 THEN 560
540 PRINT L+1;:PRINT "decimals"
550 IF CP THEN PRINT #1, L+1;:PRINT #1, "decimals"
560 IF FL=0 THEN PRINT:PRINT:IF CP THEN PRINT #1,:PRINT #1, ' No repetitions
570 IF FL=1 THEN PRINT:IF CP THEN PRINT #1,
580 GOTO 230
590 ' wait for key
600 LSET Q=MKI$(0)
610 WHILE CVI(Q)=0:MID$(Q,1)=INKEY$:WEND:RETURN
620 ' text
630 T=(31-LEN(M(I)))/2:PRINT TAB(T) M(I):RETURN
640 ' Clear previous line
650 PRINT CHR$(30);:PRINT STRING$(79,32):PRINT CHR$(30);:RETURN
